<?php
class Provider_Youtube implements Provider_Interface
{
    private $url;
    
    public function __construct($link)
    {
        $this->url = $link;
    }
    
    public function get_info()
    {
        if($open_graph = OpenGraph::fetch($this->url))
        {
           return (object) array('title' => $open_graph->title,
                                 'description' => $open_graph->description,
                                 'image' => $open_graph->image,
                                 'embed_link' => str_replace('/v/', '/embed/', $open_graph->video).'&amp;wmode=transparent',      // youtube z-index hack
                                 'url' => $this->url);  
        }
        else 
        {
           return false;
        }
    }
    
    public function get_info_view($data)
    {          
          $youtube_info_view = View::factory('embed_info/youtube', (array)$data);
          $output = array('url'    => $data->url,
                          'content'=> $youtube_info_view->render());
          
          return $output;
    }
    
    public function get_embed_view($data)
    {
        $view_data = array('embed_link' => $data->embed_link);
        $youtube_info_view = View::factory('embed_object/youtube', $view_data);
        
        return $youtube_info_view->render();
    }
} 

?>
